﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.NeighborUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.geom.*;
    import Classes.*;
    import com.greensock.*;
    import flash.filters.*;
    import Display.*;
    import flash.text.*;
    import Engine.*;

    public class FriendBarSlot extends Sprite {

        private static const PIC_POSITION:Point = new Point(5.5, 24);

        public var m_background:Bitmap;
        public var m_index:int;
        public var m_label:TextField;
        public var m_friend:Player;
        protected var m_friendMetaData:Object = null;
        public var m_profilePic:DisplayObject;
        public var m_xp:int = 0;
        public var m_level:int = 0;
        public var m_rank:int = 0;
        protected var m_isLoadingFriend:Boolean = false;
        public var m_avatarData:Object;
        public var m_fakeFriend:Boolean;
        public var m_empty:Boolean;
        private var m_slotLadder:SlotLadder;
        public var m_wishListElementCount:Number;

        public function FriendBarSlot(_arg1:int, _arg2:Boolean){
            this.m_index = _arg1;
            this.m_background = new EmbeddedArt.neighborCard();
            this.m_background.y = 16;
            addChildAt(this.m_background, 0);
            this.m_label = new TextField();
            this.m_wishListElementCount = MathUtil.random(5);
            this.m_slotLadder = new SlotLadder(this.m_wishListElementCount);
            this.m_label.selectable = false;
            addChild(this.m_label);
            this.addEventListener(MouseEvent.ROLL_OVER, this.onRollOverFriend);
            this.addEventListener(MouseEvent.ROLL_OUT, this.onRollOutFriend);
        }
        public function updateSlot(_arg1:Player, _arg2:int, _arg3:Object, _arg4:Boolean=false):void{
            this.m_friendMetaData = _arg3;
            this.m_level = _arg3.level;
            this.m_xp = _arg3.xp;
            this.m_avatarData = _arg3.avatar;
            this.m_rank = _arg2;
            this.m_fakeFriend = _arg3.fake;
            this.m_empty = _arg3.empty;
            if (this.numChildren > 1){
                this.removeChildAt(1);
            };
            this.m_friend = _arg1;
            this.m_isLoadingFriend = false;
            if (this.m_empty){
                this.setupEmptySlot();
            } else {
                if (_arg4){
                    this.setupLoadingOccupiedSpot();
                    this.m_isLoadingFriend = true;
                } else {
                    this.setupOccupiedSpot();
                };
            };
        }
        private function setupOccupiedSpot():void{
            var _local1:DisplayObject;
            var _local6:DisplayObject;
            var _local7:DisplayObject;
            var _local12:DisplayObject;
            var _local13:DisplayObject;
            var _local16:String;
            if (((this.m_friend) && (this.m_friend.snUser))){
                _local16 = this.m_friend.snUser.picture;
                if (_local16){
                    _local1 = LoadingManager.load(_local16, null, LoadingManager.PRIORITY_LOW);
                };
            };
            if (_local1 == null){
                _local1 = new EmbeddedArt.emptyAvatar();
                _local1.width = 48;
                _local1.height = 48;
            };
            _local1.x = PIC_POSITION.x;
            _local1.y = PIC_POSITION.y;
            _local1.scaleX = 1;
            _local1.scaleY = 1;
            this.m_profilePic = addChildAt(_local1, 0);
            var _local2:TextFormat = new TextFormat();
            _local2.font = EmbeddedArt.DEFAULT_FONT_NAME_BOLD;
            _local2.bold = true;
            _local2.size = 12;
            _local2.color = 0xFFFFFF;
            this.m_label.embedFonts = true;
            this.m_label.defaultTextFormat = _local2;
            this.m_label.setTextFormat(_local2);
            this.m_label.selectable = false;
            this.m_label.autoSize = TextFieldAutoSize.LEFT;
            this.m_label.text = this.m_friend.snUser.firstName;
            this.m_label.width = this.width;
            this.m_label.wordWrap = false;
            this.m_label.y = 2;
            this.m_label.x = -4;
            addChild(this.m_label);
            var _local3:TextFormat = new TextFormat();
            _local3.font = EmbeddedArt.DEFAULT_FONT_NAME_BOLD;
            _local3.bold = true;
            _local3.size = 16;
            _local3.color = 16775567;
            _local3.align = TextFormatAlign.CENTER;
            var _local4:TextField = new TextField();
            _local4.filters = [new GlowFilter(8211727, 1, 2, 2, 10)];
            _local4.embedFonts = true;
            _local4.defaultTextFormat = _local3;
            _local4.setTextFormat(_local3);
            _local4.selectable = false;
            _local4.embedFonts = true;
            _local4.width = 20;
            _local4.text = this.m_level.toString();
            _local4.x = 45;
            _local4.y = 18;
            addChild(_local4);
            var _local5:Sprite = new Sprite();
            _local5.addChild(_local6);
            _local6.x = 5;
            _local5.addChild(_local7);
            _local7.x = -5;
            _local7.y = 0;
            var _local8:TextFormat = new TextFormat();
            _local8.font = EmbeddedArt.DEFAULT_FONT_NAME_BOLD;
            _local8.bold = true;
            _local8.size = 14;
            _local8.color = EmbeddedArt.brownTextColor;
            _local8.align = TextFormatAlign.CENTER;
            var _local9:TextField = new TextField();
            _local9.embedFonts = true;
            _local9.defaultTextFormat = _local8;
            _local9.setTextFormat(_local8);
            _local9.selectable = false;
            _local9.embedFonts = true;
            _local9.width = 30;
            _local9.text = ZLoc.t("Main", "Gift");
            _local9.x = 15;
            _local5.addChild(_local9);
            var _local10:SimpleButton = new SimpleButton(_local5, _local5, _local5, _local5);
            addChild(_local10);
            _local10.y = 71;
            var _local11:Sprite = new Sprite();
            _local11.addChild(_local12);
            _local12.x = 5;
            _local11.addChild(_local13);
            _local13.x = -5;
            _local13.y = 0;
            var _local14:TextField = new TextField();
            _local14.embedFonts = true;
            _local14.defaultTextFormat = _local8;
            _local14.setTextFormat(_local8);
            _local14.selectable = false;
            _local14.embedFonts = true;
            _local14.width = 39;
            _local14.text = ZLoc.t("Main", "Visit");
            _local14.x = 11;
            _local11.addChild(_local14);
            var _local15:SimpleButton = new SimpleButton(_local11, _local11, _local11, _local11);
            addChild(_local15);
            _local15.y = 89;
        }
        private function setupEmptySlot():void{
            var _local1:Sprite = new Sprite();
            _local1.x = 35;
            _local1.y = 80;
            _local1.width = 40;
            _local1.height = 60;
            var _local2:Array = [10249488];
            var _local3:int = (this.m_rank % _local2.length);
            this.m_background.visible = false;
            var _local4:DisplayObject = new EmbeddedArt.emptyAvatar();
            _local4.x = (((_local1.width - _local4.width) / 2) + 28);
            _local4.y = (((_local1.height - _local4.height) / 2) + 65);
            addChild(_local4);
            var _local5:String = ZLoc.t("Main", "InviteNeighbor");
            var _local6:StrokeTextField = this.createSlotStatusText(_local5, 60, -1, 28);
            addChild(_local1);
        }
        private function setupLoadingOccupiedSpot():void{
            var _local1:String = ZLoc.t("Main", "LoadingNeighborSlot");
            var _local2:StrokeTextField = this.createSlotStatusText(_local1, 60, 1, 110);
            addChild(_local2);
        }
        private function createSlotStatusText(_arg1:String, _arg2:Number, _arg3:Number, _arg4:Number):StrokeTextField{
            var _local5:Array = [1322345];
            var _local6:int = (this.m_rank % _local5.length);
            var _local7:TextFormat = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, 0xFFFFFF, true, null, null, null, null, TextFormatAlign.CENTER);
            var _local8:StrokeTextField = new StrokeTextField(_local5[_local6], 1);
            _local8.toolTipText = _arg1;
            _local8.setTextFormat(_local7);
            _local8.width = 60;
            _local8.wordWrap = true;
            _local8.multiline = true;
            _local8.embedFonts = true;
            _local8.x = _arg3;
            _local8.y = _arg4;
            return (_local8);
        }
        private function onRollOverFriend(_arg1:MouseEvent):void{
            var _local2:Number;
            if (!this.m_empty){
                addChild(this.m_slotLadder);
                this.m_slotLadder.x = -7;
                this.m_slotLadder.visible = true;
                this.m_slotLadder.alpha = 0;
                _local2 = ((-(this.m_slotLadder.m_itemsCount) * this.m_slotLadder.SLOT_LADDER_SPACING) - 47);
                TweenLite.to(this.m_slotLadder, 0.2, {
                    alpha:1,
                    y:_local2
                });
            };
        }
        private function onRollOutFriend(_arg1:MouseEvent):void{
            var e:* = _arg1;
            if (!this.m_empty){
                TweenLite.to(this.m_slotLadder, 0.2, {
                    alpha:0,
                    onComplete:function ():void{
                        m_slotLadder.y = 0;
                        m_slotLadder.visible = false;
                    }
                });
            };
        }
        private function isJack():Boolean{
            if (this.m_friend){
                if (((this.m_friend.getId()) && ((this.m_friend.getId() == Player.FAKE_USER_ID)))){
                    return (true);
                };
            };
            return (false);
        }
        public function get uid():String{
            return ((this.m_friend) ? this.m_friend.uid : null);
        }

    }
}//package Display.NeighborUI 
